/**
 * 通过编号获取审批节点类型文本
 */
export const getPointTypeByNumber = (number: number) => {
  switch (number) {
    case 1:
      return '审批';
    case 2:
      return '抄送';
    case 3:
      return '子级';
    case 4:
      return '条件';
    case 5:
      return '发起';
    case 6:
      return '结束';
    default:
      return '';
  }
};
/**
 * 通过编号获取流程结果文本
 */
export const getProcessRateByNumber = (number: number) => {
  switch (number) {
    case 1:
      return '已同意';
    case 2:
      return '已退回';
    case 3:
      return '已驳回';
    case 4:
      return '审批中';
    case 5:
      return '待执行';
    default:
      return '';
  }
};

/**
 * 获取当前审批人之前所有的审核人列表，用于退回事件
 * @param pointDetails
 * @returns
 */
export const getApprovalPoint = (pointDetails: any) => {
  if (!pointDetails) return [];

  if (typeof pointDetails !== 'object') return [];
  const list: any[] = [];
  for (let i = 0; i <= pointDetails.length - 1; i++) {
    if (pointDetails[i].pointRate === 4) break;
    if (pointDetails[i].pointType === 1) list.push(pointDetails[i]);
  }
  return list;
};
/**
 * 获取当前节点到退回至节点的区间审核节点id
 * @param backNodeId
 * @param pointDetails
 * @returns
 */
export const getApprovalPointIds = (
  backNodeId: number,
  pointDetails: any[]
) => {
  let list: any[] = [];
  if (!backNodeId || !pointDetails.length) return list;
  if (typeof pointDetails !== 'object') list = [];
  if (!pointDetails.length) return list;
  let flag = false;
  for (let i = 0; i <= pointDetails.length - 1; i++) {
    if (backNodeId === pointDetails[i].id) {
      flag = true;
      continue;
    }
    if (!flag) continue;
    if (pointDetails[i].pointRate === 4) break;
    if (pointDetails[i].pointType === 1 || pointDetails[i].pointType === 2)
      list.push(pointDetails[i].id);
  }
  return list;
};
